import { asyncRoutes, constantRoutes } from '@/router'

const state = {
  newRoutes: []
}
const mutations = {
  updateRoutes(state, routes) {
    state.newRoutes = [...constantRoutes, ...routes]
  }
}
const actions = {
  filterRoutes(context, menus) {
    console.log('开始筛选路由了')
    const routes = asyncRoutes.filter(item => {
      return menus.indexOf(item.name) !== -1
    })
    context.commit('updateRoutes', routes)
    return routes
    // console.log('这是context', context)
    // console.log('这是store', this.$store)
    // console.log('permission里的1')

    // console.log('这是menus', menus)
    // console.log('这是筛选出来的路由', routes)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
